﻿namespace bin.imgshow
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("将ttimg 反向拆解为调色板（如果有）和png!");

            ttbit.form.ImgData img = new ttbit.form.ImgData();
            var filename = args[0];
            using (var fs = System.IO.File.OpenRead(filename))
            {
                using(var br =new BinaryReader(fs))
                {
                    img.Read(br);
                }
            }
            ImageData data;
            ImageData datapal;
            ImgUnpack.UnPack(img, out data, out datapal);
            StbImageWriteSharp.ImageWriter writer = new StbImageWriteSharp.ImageWriter();
            using (var fs = System.IO.File.OpenWrite(filename + "_src.png"))
            {
                writer.WritePng(data.data, data.width, data.height, StbImageWriteSharp.ColorComponents.RedGreenBlueAlpha, fs);
            }
            if(datapal!=null)
            {
                using (var fs = System.IO.File.OpenWrite(filename + "_pal.png"))
                {
                    writer.WritePng(datapal.data, datapal.width, datapal.height, StbImageWriteSharp.ColorComponents.RedGreenBlueAlpha, fs);
                }
            }
        }
    }
}